package com.example.worktwo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import org.w3c.dom.Text;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    public TextView Text;
    private Button btn1;
    private Button btn2;
    private Button btn3;
    private Button btn4;
    private Button btn5;
    @BindView(R.id.btn6)
    Button btn6;//去逛逛
    private Button btn7;
    private Button btn8;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        Text=findViewById(R.id.text);
        btn1=findViewById(R.id.btn1);
        btn2=findViewById(R.id.btn2);
        btn3=findViewById(R.id.btn3);
        btn4=findViewById(R.id.btn4);
        btn5=findViewById(R.id.btn5);
        btn7=findViewById(R.id.btn7);
        btn8=findViewById(R.id.btn8);
        //1.使用activity绑定监听器
        btn1.setOnClickListener(this);
        //2.使用匿名内部类绑定监听器
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Text.setText("点击了采用匿名内部类绑定的监听器");
            }
        });
        //4.使用内部类绑定监听器
        btn4.setOnClickListener(new OnClick());
        //5.采用外部类绑定监听器
        btn5.setOnClickListener(new OutsideClass(this,Text));
        btn7.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, ConfigurationTest.class);
                startActivity(intent);
            }
        });
        btn8.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, ProgressDialogTest.class);
                startActivity(intent);
            }
        });
    }

    //activity实现
    @Override
    public void onClick(View v) {
        Text.setText("点击了采用activity绑定的监听器");
    }
    //内部类实现
    class OnClick implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            Text.setText("点击了采用内部类绑定的监听器");
        }
    }
    //绑定到标签
    public void clickHandler(View Source){
        Text.setText("点击了采用标签绑定的监听器");
    }


    //绑定butterknife
    @butterknife.OnClick({R.id.btn6})
    void onViewClicked(View v) {
        Text.setText("点击了采用Butterknife绑定的监听器");
        }
}
